﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using BLL;
using MODEL;
using System.Collections.Generic;

public partial class Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            string txtName = Request.Form["txtName"];
            string txtPwd = Request.Form["txtPwd"];
            string txtCnName = Request.Form["txtCnName"];
            string selClass = Request.Form["selClass"];
            string gender = Request.Form["gender"];
            string txtTel = Request.Form["txtTel"];

            StudentModel model = new StudentModel();
            model.SCID = Convert.ToInt32(selClass);
            model.SCnName = txtCnName;
            if (gender == "1")
            {
                model.SGender = false;
            }
            else
            {
                model.SGender = true;
            }
            model.SIsDel = false;
            model.SLoginName = txtName;
            model.SPwd = txtPwd;
            model.STel = txtTel;
            model.SClass = null;
            model.SAddtime = DateTime.Now;

            if (new StudentBLL().AddNew(model))
            {
                Response.Redirect("Login.aspx?msg=注册成功");
            }
            else
            {
                Response.Redirect("Login.aspx?msg=注册失败");
            }

            //Response.Write("txtName=" + txtName);
            //Response.Write("txtPwd=" + txtPwd);
            //Response.Write("txtCnName=" + txtCnName);
            //Response.Write("selClass=" + selClass);
            //Response.Write("gender=" + gender);
            //Response.Write("txtTel=" + txtTel);
        }
        else
        {
        }
    }

    protected string GetClasses()
    {
        StringBuilder sb = new StringBuilder();
        List<ClassModel> list =  new ClassesBLL().GetAllClass();
        foreach (ClassModel cla in list)
        {
            sb.Append("<option value="+cla.CID+">"+cla.CName+"</option>");
        }
        return sb.ToString();
    }
}
